import { createRouter, createWebHistory } from "vue-router";
import useRouterGuard from "./guard";
// 定义路由组件路径
const routes: any = [
  {
    path: "/",
    name: "root",
    redirect: "/first",
    component: () => import("@/layout/index.vue"),
    children: [
      {
        path: "/first",
        name: "first",
        component: () => import("@/pages/First.vue"),
      },
      {
        path: "/login",
        name: "login",
        component: () => import("@/pages/login/index.vue"),
      },
      {
        path: "/user",
        name: "user",
        component: () => import("@/pages/user/index.vue"),
      },
      {
        path: "/manage",
        name: "manage",
        component: () => import("@/pages/manage/index.vue"),
      },
      {
        path: "/cm",
        name: "cm",
        component: () => import("@/pages/CodeMirror.vue"),
      },
      {
        path: "/about",
        name: "about",
        component: () => import("@/pages/about/index.vue"),
      },
    ],
  },
  {
    path: "/exception",
    name: "exception",
    redirect: "/exception/404",
    children: [
      {
        path: "404",
        name: "exception-404",
        component: () => import("@/pages/exception/404.vue"),
      },
    ],
  },
];
// 创建Router对象
const router = createRouter({
  history: createWebHistory(),
  routes,
  // 路由跳转时,始终滚动到左顶部
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 加载路由导航守卫
useRouterGuard(router);

// 导出对象
export default router;
